@extends('admin.layouts.app')
@section('content')

                        <!-- Page-Title -->
                        <div class="row">
                            <div class="col-sm-12">
                                <h4 class="page-title">客户管理</h4>
                                <ol class="breadcrumb">
                                    <li><a href="{{url('zadmin')}}">系统</a></li>
                                   
                                    <li class="active">客户列表</li>
                                </ol>
                            </div>
                        </div>
                        
                        <div class="row">
                        	<div class="col-lg-12">
                        		<div class="card-box">
                        			<div class="row">
			                        	<div class="col-sm-6">
			     <form role="form">
			         <div class="form-group contact-search col-sm-6">
			           <input type="text" id="search" name="keyword" class="form-control" placeholder="输入客户姓名/电话/车牌号搜索">
			            
			         </div>
               <div class="col-sm-3">
                  <button type="button" id="srcBtn" class="btn btn-white btn-sm"><i class="fa fa-search">搜索</i></button>
               </div>
               <div class="col-sm-3">
                 
                    <button  class="btn btn-success btn-sm" id="exportBtn" type="button"><i class="md  md-file-download">导出</i></button>
                  
               </div>
			     </form>
			     </div>


                <div class="col-sm-6">
                <form enctype="multipart/form-data" method="post" action="{{url('zadmin/clients/import')}}" id="form1">                                  
                  <div class="col-sm-6">
                    <input type="file" required=""  name="excel" class="form-control" >
                  
                  </div>
                  <div class="col-sm-2">
                    <button  class="btn btn-danger  waves-effect waves-light m-b-30 btn-sm"><i class="md  md-file-upload">导入</i></button>
                  </div>
                  <div class="col-sm-2">
                    <a href="{{url('excel/批量导入客户模板.xlsx')}}"  class="btn btn-default  waves-effect waves-light m-b-30 btn-sm"><i class="md  md-file-download">模板</i></a>
                  </div>
                  <div class="col-sm-1"> 
                                  <a href="{{url('zadmin/clients/create')}}" class="btn btn-primary  waves-effect waves-light m-b-30 btn-sm"  
                                  ><i class="md md-add"></i>添加</a>
                                </div>
                  {{csrf_field()}}
                </form>
                </div>
			        </div>

                              @if(session('rs'))
                              <div class="alert alert-{{session('rs')['status']}}">
                                {{ session('rs')['msg'] }}
                              </div>
                              @endif
			                        
                        			<div class="table-responsive">
                                        <table class="table table-hover">
                                        	<thead>
												<tr>
													<th style="min-width: 35px;">
													ID
                                                        
													</th>
													<th>编号</th>
													<th>名称</th>
                          <th>电话</th>
                          <th>车辆数量</th>
                          <th>消费次数</th>
                          <th>消费金额</th>

                         
                         
													<th style="width: 200px;">操作</th>
												</tr>
											</thead>
											
                      <tbody>

                      @foreach($list as $v)
                          <tr>
                              <td>
                                  {{$v->id}}
                                                        
                                                      
                              </td>
                                                    
                  <td>
                      {{$v->code}}
                  </td>
                  <td>{{$v->name}}</td>
                  <td>
                      {{$v->phone}}
                  </td>
                  <td>
                      <a href="{{url('zadmin/cars')}}?client_id={{$v->id}}">
                        {{$v->car_num}}</a>
                  </td>
                  <td>
                      <a href="{{url('zadmin/task')}}?client_id={{$v->id}}">{{$v->task->count()}}</a>
                  </td>
                  <td>
                      {{$v->task->sum('total_money')}}
                  </td>                             
                                                    
                                                    
                                                
                                                    
                                                   
                  <td>
                    <a href="{{url('zadmin/client-users')}}?client_id={{$v->id}}"><i class="md  md-perm-contact-cal"></i>联系人</a>&nbsp;&nbsp;
                    <a href="{{url('zadmin/clients/'.$v->id.'/edit')}}" ><i class="md md-edit"></i>修改</a>&nbsp;&nbsp;
                    <a href="{{url('zadmin/clients',$v->id)}}" data-method="delete" 
  data-token="{{csrf_token()}}" data-confirm="确定删除吗?"><i class="md md-close"></i>删除</a>
                  </td>
              </tr>
                                            @endforeach    
                                                
                                               
                                               
                                                
                                               
                                                
                                            
                                            </tbody>
                                        </table>
                                    </div>

                                     {{ $list->links() }}
                        		</div>
                                
                            </div> <!-- end col -->

                            
                        </div>
@endsection
                        
                        
                        

                  
            
@section('js')
    <script type="text/javascript">
    $('#checkAll').click(function () {    
      $('input:checkbox').prop('checked', this.checked);    
    });

    $('#srcBtn').on('click',function(){
      var url = "{{url('zadmin/clients')}}";
      $('#form1').attr('action',url).submit(); 
    });
    $('#exportBtn').on('click',function(){
      var url = "{{url('zadmin/clients/export')}}";
      $('#form1').attr('action',url).submit(); 
    });


  $('.bathDel').on('click',function(){
    var ids = $('.check_class:checked').map(function() {
      return this.value;
    }).get();
    if(ids==''){
      alert('请选择要删除的数据');return;
    }
    var url="{{url('zadmin/client/bath-del')}}";
    var data = {};
    data.ids = ids;
    data._token = "{{csrf_token()}}";
    $.post(url,data,function(rs){
      if(rs.status==true) {
        window.location.reload();
      }
    });
    console.info(ids);
  });
    
    
  
</script>
    @endsection          
       

           



    
        
    
